﻿<?php
ini_set('date.timezone','Asia/Shanghai');

if($_GET['random'] != '20130826') {
    return ;
}


define('DBPAS',"coolchuan2012");
//define('DBPAS',"123456");
$link = mysql_connect("localhost","root",DBPAS); 

mysql_select_db("catchappdataall", $link);
mysql_query('SET NAMES UTF8');


//$apps_url_page_header = "http://openbox.mobilem.360.cn/AppStore/getRecomendAppsBytype?type=1&os=17&model=HTC+Sensation&cpu=pyramid&&screen_size=960x540&startCount=21&start=0&count=".ONCECATCHCOUNT;
//$apps_url_app_all_list = "http://openboxcdn.mobilem.360.cn/AppStore/getTopapplist?type=1&os=17&model=HTC+Sensation&cpu=pyramid&&screen_size=960x540&order=down&start=0&count=".ONCECATCHCOUNT;
define('LOGFORSUCCESS',0);


$jifeng_arr = get_countarr("jifeng");

$anzhi_arr = get_countarr("anzhi");
$wandoujia_arr = get_countarr("wandoujia");
$baidu_arr = get_countarr("baidu");

showtable($jifeng_arr,"机锋");
showtable($baidu_arr,"百度");
showtable($wandoujia_arr,"豌豆荚");
showtable($anzhi_arr,"安智");

function showtable($market,$marketname)
{
	echo "<table align='center' border=1 width='600px'>";

	echo "<tr>";
	echo "<td>app总数：".$market["info"];
	echo "</td>";
	echo "<td>$marketname";
	echo "</td>";
	echo "<td>排行<br />";
	foreach ($market['rank'] as $data_arr)
	{
		echo $data_arr['time']."&nbsp&nbsp".$data_arr['count']."<br />";
	}
	echo "</td>";
	
	echo "<td>下载评分数据<br />";
	foreach ($market['score'] as $data_arr)
	{
		echo $data_arr['time']."&nbsp&nbsp".$data_arr['count']."<br />";
	}
	echo "</td>";
	
	echo "</tr>";
	
	echo "</table>";
}





function get_countarr($market)
{
	$count_arr = array();
	$count_arr['info'] = 0;
	$count_arr['rank'] = array();
	$count_arr['score'] = array();
	
	$day_arr = array();
	$day_arr[] = date("Y-m-d");
	for($i=0;$i<=7;$i++)
	{
		$day_arr[] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));
	}
	
	$link = mysql_connect("localhost","root",DBPAS); 

	$sql = 'select count(id) as count from jk_apps_info_'.$market.' where IsDeleted=0 '; 
	$rs = mysql_query($sql, $link);
  	while($row=mysql_fetch_array($rs))        
  	{
  		$count_arr['info'] = $row['count'];
  	}
  	
	$sql = 'select count(distinct(app_id)) as count,time from jk_apps_data_mobile_'.$market.'_'.date('Ym',time()).' group by time order by time ';
	$rs = mysql_query($sql, $link);
  	while($row=mysql_fetch_array($rs))        
  	{
  		if(in_array($row['time'],$day_arr))
  		{
  			$data_temp['count'] = $row['count'];
  			$data_temp['time'] = $row['time'];
  			$count_arr['rank'][] = $data_temp;
  		}
  	}
  	
  	$today = date("Y-m-d");
	$sql = 'select count(distinct(app_id)) as count,time from jk_apps_score_data_mobile_'.$market.'_'.date('Ym',time()).' group by time order by time ';
	$rs = mysql_query($sql, $link);
  	while($row=mysql_fetch_array($rs))        
  	{
  		if(in_array($row['time'],$day_arr))
  		{
  			$data_temp['count'] = $row['count'];
  			$data_temp['time'] = $row['time'];
  			$count_arr['score'][] = $data_temp;
  		}
  	}
  	
	return $count_arr;
}





?>